package gui.dialog;

import gui.TuristAssistant;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.example.www.communication.MailService.EMail;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
/**
 * Dialogo que realiza la funcionalidad de mostrar el contenido de un e-mail.
 */
public class CommReadEMailDialog extends org.eclipse.swt.widgets.Dialog {
	private EMail	email;
	
	private Shell	dialogShell;
	private Text	swttxtaBody;
	private Label	swtlblSubject;
	private Label	swtlblFrom;
	private Text	swttxtFrom;
	private Text	swttxtSubject;
	
	/**
	 * Auto-generated main method to display this org.eclipse.swt.widgets.Dialog
	 * inside a new Shell.
	 */
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			CommReadEMailDialog inst = new CommReadEMailDialog(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Constructor basado en el constructor super. 
	 */
	public CommReadEMailDialog(Shell parent, int style) {
		super(parent, style);
	}
	
	/**
	 * Muetra el dialogo en modo modal. <BR/>
	 * Antes de invocar este metodo se deve setear el e-mail mediante
	 * {@link #setEmail(EMail)}.
	 */
	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM
					| SWT.APPLICATION_MODAL);
			
			dialogShell.setLayout(new FormLayout());
			dialogShell.setText("Read e-Mail");
			dialogShell
					.setImage(new Image(Display.getCurrent(),
							"resource/tango-icon-theme-0.8.90/16x16/actions/edit-find.png"));
			{
				swttxtaBody = new Text(dialogShell, SWT.MULTI | SWT.WRAP
						| SWT.V_SCROLL | SWT.BORDER);
				FormData swttxtaBodyLData = new FormData();
				swttxtaBodyLData.width = 399;
				swttxtaBodyLData.height = 190;
				swttxtaBodyLData.left = new FormAttachment(32, 1000, 0);
				swttxtaBodyLData.top = new FormAttachment(214, 1000, 0);
				swttxtaBodyLData.bottom = new FormAttachment(956, 1000, 0);
				swttxtaBodyLData.right = new FormAttachment(978, 1000, 0);
				swttxtaBody.setLayoutData(swttxtaBodyLData);
			}
			{
				swttxtSubject = new Text(dialogShell, SWT.BORDER);
				FormData swttxtSubjectLData = new FormData();
				swttxtSubjectLData.width = 371;
				swttxtSubjectLData.height = 11;
				swttxtSubjectLData.left = new FormAttachment(142, 1000, 0);
				swttxtSubjectLData.top = new FormAttachment(128, 1000, 0);
				swttxtSubjectLData.bottom = new FormAttachment(185, 1000, 0);
				swttxtSubjectLData.right = new FormAttachment(974, 1000, 0);
				swttxtSubject.setLayoutData(swttxtSubjectLData);
				swttxtSubject.setEditable(false);
			}
			{
				swttxtFrom = new Text(dialogShell, SWT.BORDER);
				FormData swttxtFromLData = new FormData();
				swttxtFromLData.width = 372;
				swttxtFromLData.height = 13;
				swttxtFromLData.left = new FormAttachment(142, 1000, 0);
				swttxtFromLData.top = new FormAttachment(54, 1000, 0);
				swttxtFromLData.bottom = new FormAttachment(110, 1000, 0);
				swttxtFromLData.right = new FormAttachment(974, 1000, 0);
				swttxtFrom.setLayoutData(swttxtFromLData);
				swttxtFrom.setText(TuristAssistant.appContextProperties
						.getProperty(TuristAssistant.USERID_PROPERTY));
				swttxtFrom.setEditable(false);
				swttxtFrom.setBounds(63, 12, 372, 13);
			}
			{
				swtlblSubject = new Label(dialogShell, SWT.NONE);
				FormData swtlblSubjectLData = new FormData();
				swtlblSubjectLData.width = 40;
				swtlblSubjectLData.height = 17;
				swtlblSubjectLData.left = new FormAttachment(27, 1000, 0);
				swtlblSubjectLData.top = new FormAttachment(128, 1000, 0);
				swtlblSubjectLData.bottom = new FormAttachment(185, 1000, 0);
				swtlblSubjectLData.right = new FormAttachment(115, 1000, 0);
				swtlblSubject.setLayoutData(swtlblSubjectLData);
				swtlblSubject.setText("Subject:");
			}
			{
				swtlblFrom = new Label(dialogShell, SWT.NONE);
				FormData swtlblFromLData = new FormData();
				swtlblFromLData.width = 26;
				swtlblFromLData.height = 13;
				swtlblFromLData.left = new FormAttachment(27, 1000, 0);
				swtlblFromLData.top = new FormAttachment(54, 1000, 0);
				swtlblFromLData.bottom = new FormAttachment(110, 1000, 0);
				swtlblFromLData.right = new FormAttachment(86, 1000, 0);
				swtlblFrom.setLayoutData(swtlblFromLData);
				swtlblFrom.setText("From:");
			}
			
			if (this.email != null) {
				swttxtFrom.setText(email.getSender());
				swttxtSubject.setText(email.getSubject());
				swttxtaBody.setText(email.getBody());
			}
			
			dialogShell.layout();
			dialogShell.pack();
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * @param email
	 *        el email a mostrar.
	 */
	public void setEmail(EMail email) {
		this.email = email;
	}
	
}
